<template>
  <div class="system-dic-dialog-container">
    <el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="520px">
      <el-form ref="dicDialogFormRef" :model="state.ruleForm" label-width="90px">
        <el-form-item label="质量维度">
          <el-input v-model="state.ruleForm.name" placeholder="请输入质量维度" clearable></el-input>
        </el-form-item>
        <el-form-item label="质量指标">
          <el-input v-model="state.ruleForm.type" placeholder="请输入耕地质量指标" clearable></el-input>
        </el-form-item>
        <el-form-item label="编码">
          <el-input v-model="state.ruleForm.type" placeholder="请输入编码" clearable></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="state.ruleForm.type" type="textarea" placeholder="备注" clearable></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="onCancel">取 消</el-button>
          <el-button type="primary" @click="onSubmit">{{ state.dialog.submitTxt }}</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts" name="systemDicDialog">
import { reactive, ref } from 'vue';

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);

// 定义变量内容
const dicDialogFormRef = ref();
const state = reactive({
  ruleForm: {} as any,
  dialog: {
    isShowDialog: false,
    type: '',
    title: '',
    submitTxt: '',
  },
});

// 打开弹窗
const openDialog = (type: string, row: RowDicType) => {
  if (type === 'edit') {
    state.ruleForm = row;
    state.dialog.title = '修改';
    state.dialog.submitTxt = '修 改';
  } else {
    state.dialog.title = '新增';
    state.dialog.submitTxt = '新 增';
    // 清空表单，此项需加表单验证才能使用
    // nextTick(() => {
    // 	dicDialogFormRef.value.resetFields();
    // });
  }
  state.dialog.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
  state.dialog.isShowDialog = false;
};
// 取消
const onCancel = () => {
  closeDialog();
};
// 提交
const onSubmit = () => {
  closeDialog();
  emit('refresh');
  // if (state.dialog.type === 'add') { }
};

// 暴露变量
defineExpose({
  openDialog,
});
</script>
